<template>
  <view style="padding: 8rpx 32rpx;padding-top: 44px;">
    <view style="position: fixed;z-index: 999; top: 0;left: 0;width: 100%;padding: 0 32rpx; background-color: #fff;">
      <image src="/static/lzl/Search@2x.png" class="img_left" mode=""></image>
      <input
        style="width: 100%;height: 88rpx;padding-left: 102rpx;box-sizing: border-box; border-bottom: 2rpx solid #858380;"
        type="text"
        v-model="value"
        @confirm="input"
        @input="inp"
        placeholder="请搜索"
        name=""
        id=""
      />
      <image @click.stop="clean" class="img_right" src="/static/lzl/close-circle@2x.png" mode=""></image>
    </view>
    <!-- /下面的商品 -->
    <view class="shoop">
      <view class="shoop_son" v-for="(item, index) in list" @click="toDetlis(item)" :key="index">
        <image :src="item.image" style="width: 330rpx;height: 400rpx;" mode=""></image>
        <view class="price">
          <view class="bt">{{ item.title }}</view>
          <view class="btPrice">￥{{ item.price }}</view>
        </view>
      </view>
    </view>
    <view v-show="list.length == 0" style="font-size: 32rpx;margin-top: 50%;margin-left: 50%;transform: translateX(-20%);color: #c8c8c8;" class="">暂无商品</view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      value: '',
      list: [],
      page: 1
    };
  },
  onReachBottom() {
    if (this.list.length < this.page * 10) return;
    this.page++;
    this.init();
  },
  onShow() {
    this.init();
  },
  methods: {
    toDetlis(item) {
      uni.navigateTo({
        url: '/pages/details/details?id=' + item.id
      });
    },
    inp() {
      if (!this.value) {
        this.page = 1;
        this.init();
      }
    },
    // 输入搜索内容后
    input() {
      this.page = 1;
      let n = null;
      clearTimeout(n);
      n = setTimeout(() => {
        this.list = [];
        this.init();
      }, 1000);
    },
    async init() {
      let m = await this.$api.lists({
        page: this.page,
        category_id: -1,
        keywords: this.value
      });
      // this.list = n.data.data;
      if (this.page != 1) {
        this.list = [...this.list, ...m.data.data];
      } else {
        this.list = m.data.data;
      }
    },
    // 点击搜索x给x调
    clean() {
      console.log(1451465);
      this.value = '';
      this.page = 1;
      this.init();
    }
  }
};
</script>

<style lang="scss">
* {
  box-sizing: border-box;
}
.shoop {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 34rpx;
  .shoop_son {
    width: 330rpx;
    margin-bottom: 32rpx;
    .price {
      text-align: center;
      .bt {
        margin-top: 16rpx;
        margin-bottom: 8rpx;
        font-size: 28rpx;
        font-family: PingFang SC-Regular, PingFang SC;
        font-weight: 400;
        color: #0a0a09;
        overflow: hidden; //超出文本隐藏

        text-overflow: ellipsis; ///超出部分省略号显示

        display: -webkit-box; //弹性盒模型

        -webkit-box-orient: vertical; //上下垂直

        -webkit-line-clamp: 2; //自定义行数
      }
      .btPrice {
        font-size: 28rpx;
        font-family: PingFang SC-Bold, PingFang SC;
        font-weight: bold;
        color: #5c5a55;
        line-height: 48rpx;
      }
    }
  }
}
.img_left {
  position: absolute;
  left: 44rpx;
  top: 20rpx;
  width: 48rpx;
  height: 48rpx;
}
.img_right {
  position: absolute;
  right: 44rpx;
  top: 30rpx;
  width: 32rpx;
  height: 32rpx;
  z-index: 9999;
}
</style>
